<template>
    <div>
        <Card class="wrap" :bordered="false" :dis-hover="true">
            <Form :model="search" :label-width="80">
                <div class="table-top-wrap">
                    <div>
                        <div>
                            <!-- <Button style="background:#009688;color:#fff" @click="handleModel">
                                <Icon type="md-add" size="18" />创建订单
                            </Button>-->
                            <!-- <Button class="features-btn btn-auto-m">
                                <Icon type="md-calendar" size="18" />作废
                            </Button>-->
                            <Button
                                @click="changemodel"
                                style="margin-right:10px;background:#009688;color:#fff"
                            >订单确认</Button>
                            <Button
                                @click="assign"
                                style="margin-right:10px;background:#009688;color:#fff"
                            >任务指派</Button>
                            <Button
                                @click="arrive"
                                style="margin-right:10px;background:#009688;color:#fff"
                            >订单完成</Button>
                            <Button @click="refund" style="background:#009688;color:#fff">退款</Button>
                        </div>
                    </div>
                    <div class="table-top-wrap-bottom">
                        <div class="table-top-wrapper">
                            <Select v-model="search.state" clearable placeholder="状态">
                                <Option
                                    v-for="item in state"
                                    :value="item.value"
                                    :key="item.value"
                                >{{ item.label }}</Option>
                            </Select>
                        </div>
                        <div class="table-top-wrapper">
                            <DatePicker
                                type="date"
                                placeholder="预约开始时间"
                                style="width: 200px"
                                v-model="search.startDate"
                            ></DatePicker>
                        </div>
                        <div class="table-top-wrapper">
                            <DatePicker
                                type="date"
                                placeholder="预约结束时间"
                                style="width: 200px"
                                v-model="search.endDate"
                            ></DatePicker>
                        </div>
                        <div class="table-top-wrapper">
                            <i-input v-model="search.service" placeholder="预约人/联系方式"></i-input>
                        </div>
                        <div>
                            <Button
                                icon="ios-search"
                                @click="handleSearch"
                                class="search-btn"
                                style="background:#009688;color:#fff"
                            >搜索</Button>
                        </div>
                    </div>
                </div>
            </Form>
            <Table
                :height="tableHeight"
                border
                :columns="columns"
                :data="list"
                @on-selection-change="selectmodel"
            >
                <template slot-scope="{ row }" slot="BookingTime">{{ row.BookingTime | BookDateCn }}</template>
                <template slot-scope="{ row }" slot="State">{{ row.State | stateCn }}</template>
                <template slot-scope="{ row }" slot="CreateTime">{{ row.CreateTime | CreateTimeCn }}</template>
                <template slot-scope="{ row }" slot="action">
                    <Button
                        v-if="Number( row.State)<=2"
                        type="primary"
                        size="small"
                        style="margin-right: 5px;background:#5ab1ef;color:#fff;border:#5ab1ef;"
                        @click="ChangeAppointment(row)"
                    >修改</Button>
                    <!-- v-if="row.State!=='4'" -->
                    <Button
                        style="margin-right: 5px;background:#ff9900;color:#fff;border:#5ab1ef;"
                        type="error"
                        size="small"
                        @click="see(row.ID)"
                    >查看</Button>
                </template>
            </Table>
            <div class="page-wrap">
                <div class="page-wrap-total">共 {{total}} 条</div>
                <div>
                    <Page
                        placement="top"
                        :total="total"
                        :current="current"
                        @on-change="changePage"
                        @on-page-size-change="changePageSize"
                        show-sizer
                    ></Page>
                </div>
            </div>
        </Card>
        <Modal :mask-closable="false" v-model="isModal" :title="ModalTitle" width="700">
            <div v-if="isModal">
                <Form ref="formItem" :model="formItem" :rules="ruleValidate" :label-width="100">
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="预约人" prop="appointmentName">
                                <Select
                                    v-model="formItem.appointmentName"
                                    filterable
                                    remote
                                    :remote-method="remoteMethod1"
                                    :loading="loading1"
                                >
                                    <Option
                                        v-for="option in vipList"
                                        :value="option.value"
                                        :key="option.value"
                                    >{{option.label}}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="陪诊医院" prop="hospital">
                                <Select
                                    v-model="formItem.hospital"
                                    filterable
                                    remote
                                    :remote-method="remoteMethod2"
                                    :loading="loading1"
                                >
                                    <Option
                                        @click.native="handleHospChange(item)"
                                        v-for="item in hospList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.HospName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="患者姓名" prop="patientName">
                                <i-input v-model="formItem.patientName" placeholder="请输入患者姓名"></i-input>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="陪诊科室" prop="Department">
                                <Select
                                    v-model="formItem.Department"
                                    placeholder="请选择科室"
                                    style="width:200px;margin-right:20px"
                                >
                                    <Option
                                        @click.native="handleDepChange(item)"
                                        v-for="item in DepartmentList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.Dname }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="患者电话" prop="phone">
                                <i-input v-model="formItem.phone" placeholder="请输入患者电话"></i-input>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="预约日期" prop="date">
                                <DatePicker
                                    type="date"
                                    value="yyyy-MM-dd"
                                    placeholder="请输入预约日期"
                                    v-model="formItem.date"
                                ></DatePicker>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="患者年龄" prop="age">
                                <i-input v-model="formItem.age" placeholder="请输入患者年龄"></i-input>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="预约时间" prop="time">
                                <i-input v-model="formItem.time" placeholder="请输入预约时间"></i-input>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="患者性别" prop="sex">
                                <RadioGroup v-model="formItem.sex">
                                    <Radio label="1">男</Radio>
                                    <Radio label="0">女</Radio>
                                </RadioGroup>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="就诊类型" prop="type">
                                <RadioGroup v-model="formItem.type">
                                    <Radio label="1">初诊</Radio>
                                    <Radio label="2">复诊</Radio>
                                    <Radio label="3">检查</Radio>
                                </RadioGroup>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="行动方便" prop="action">
                                <RadioGroup v-model="formItem.action">
                                    <Radio label="1">是</Radio>
                                    <Radio label="0">否</Radio>
                                </RadioGroup>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="预约方式" prop="mode">
                                <RadioGroup v-model="formItem.mode">
                                    <Radio label="1">已预约</Radio>
                                    <Radio label="2">代理预约</Radio>
                                    <Radio label="3">现场挂号</Radio>
                                </RadioGroup>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="陪诊类型" prop="service">
                                <Select v-model="formItem.service" clearable placeholder="陪诊类型">
                                    <Option
                                        @click.native="handleSelectChange(item)"
                                        v-for="item in serviceList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.ServiceName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <div
                                v-if="formItem.service"
                                style="line-height:30px;margin-left:20px;color:#009688;font-size:16px"
                            >/*&nbsp;&nbsp; {{formItem.cost}}&nbsp; &nbsp; */</div>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="所属门店">
                                <Select
                                    v-model="formItem.shop"
                                    placeholder="请选择门店"
                                    style="width:200px;margin-right:20px"
                                >
                                    <Option
                                        @click.native="handleShopChange(item)"
                                        v-for="item in shopList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.ShopName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="服务人员">
                                <!-- <i-input v-model="formItem.serviceName" placeholder="请输入服务人员"></i-input> -->
                                <Select
                                    v-model="formItem.serviceName"
                                    placeholder="请输入服务人员"
                                    style="width:200px;margin-right:20px"
                                >
                                    <Option
                                        v-for="item in shopUserList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.RealName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 24}">
                            <FormItem label="患者地址" prop="FromAddress">
                                <i-input v-model="formItem.FromAddress" placeholder="患者地址"></i-input>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col :lg="{ span: 24}">
                            <FormItem label="主诉病情">
                                <i-input v-model="formItem.disease" placeholder="请输入主要病症"></i-input>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 24}">
                            <FormItem label="备注">
                                <i-input v-model="formItem.remarks" placeholder="备注"></i-input>
                            </FormItem>
                        </i-col>
                    </Row>
                </Form>
            </div>
            <div slot="footer">
                <Button size="large" @click="handleFromClose">取消</Button>
                <Button type="primary" size="large" @click="handleSubmit('formItem',ModalTitle)">确定</Button>
            </div>
        </Modal>
        <Modal :mask-closable="false" v-model="seeModal" width="700">
            <div v-if="seeModal">
                <drugsTable ref="drugsTable" :data="singleList" :message="message"></drugsTable>
            </div>
            <div slot="footer" style="text-align:center;">
                <!-- <Button size="large" @click="handleClose()">作废</Button> -->
                <Button type="primary" size="large" @click="handlePrint()">打印</Button>
            </div>
        </Modal>
        <Modal :mask-closable="false" v-model="assignModal" width="700" title="任务指派">
            <div v-if="assignModal">
                <Form ref="formItem" :model="formItem" :label-width="100">
                    <Row>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="所属门店">
                                <Select
                                    v-model="formItem.shop"
                                    placeholder="请选择门店"
                                    style="width:200px;margin-right:20px"
                                >
                                    <Option
                                        @click.native="handleShopChange(item)"
                                        v-for="item in shopList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.ShopName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col :lg="{ span: 12}">
                            <FormItem label="服务人员">
                                <!-- <i-input v-model="formItem.serviceName" placeholder="请输入服务人员"></i-input> -->
                                <Select
                                    v-model="formItem.serviceName"
                                    placeholder="请输入服务人员"
                                    style="width:200px;margin-right:20px"
                                >
                                    <Option
                                        @click.native="handlefuwuChange(item)"
                                        v-for="item in shopUserList"
                                        :value="item.ID"
                                        :key="item.ID"
                                    >{{ item.RealName }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                    </Row>
                </Form>
            </div>
            <div slot="footer" style="text-align:center;">
                <Button size="large" @click="handleassignModal()">取消</Button>
                <Button type="primary" size="large" @click="assignSub()">确认</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import {
    shopData,
    GetGridJsonList,
    GetUser,
    HospitalList,
    CreateNewAccompany,
    GetGridJson,
    OrderEdit,
    GetOrderDetail,
    GetSelectJson,
    GetShopUserList,
    AdRefund,
    BindService,
    OverOrder
} from './service'
import drugsTable from './drugsTable.vue'
import moment from 'moment'
export default {
    name: 'usersList',

    data() {
        return {
            loading: false,
            isModal: false, //显示新增
            seeModal: false,
            assignModal: false,
            assignForm: {
                ServiceID: '',
                ServiceName: ''
            },
            formItem: {
                remarks: '',
                disease: '',
                ServiceID: '',
                serviceName: '',
                shop: '',
                Department: '',
                mode: '',
                type: '',
                action: '',
                cost: '',
                date: '',
                appointmentName: '',
                sex: '',
                age: '',
                phone: '',
                patientName: '',
                hospital: '',
                service: '',
                OrderServerName: '',
                HospName: '',
                ToAddress: '',
                FromAddress: '',
                ID: '',
                HospDepName: '',
                time: ''
            }, //新增表单
            search: {
                state: '',
                startDate: '',
                endDate: '',
                service: ''
            }, //查询条件
            state: [
                {
                    value: 0,
                    label: '待付款'
                },
                {
                    value: 1,
                    label: '已付款'
                },
                {
                    value: 2,
                    label: '已确认'
                },
                {
                    value: 3,
                    label: '已接单'
                },
                {
                    value: 4,
                    label: '已开始'
                },
                {
                    value: 5,
                    label: '已完成'
                },
                {
                    value: 6,
                    label: '已取消'
                },
                {
                    value: 7,
                    label: '已退款'
                },
                {
                    value: 8,
                    label: '陪诊完成'
                },
                {
                    value: 9,
                    label: '评价完成'
                },
                {
                    value: 10,
                    label: '全部完成'
                }
            ],
            DepartmentList: [],
            costList: [],
            ModalTitle: '信息修改', //新增或修改
            ruleValidate: {
                FromAddress: [
                    {
                        required: true,
                        message: '请填写患者住址',
                        trigger: 'blur'
                    }
                ],
                shop: [
                    {
                        required: true,
                        message: '请选择门店',
                        type: 'number',
                        trigger: 'change'
                    }
                ],
                serviceName: [
                    {
                        required: true,
                        message: '请选择服务人员',
                        type: 'number',
                        trigger: 'change'
                    }
                ],
                appointmentName: [
                    {
                        required: true,
                        message: '请填写预约人姓名',
                        type: 'number',
                        trigger: 'change'
                    }
                ],
                Department: [
                    {
                        required: true,
                        message: '请选择陪诊科室',
                        type: 'number',
                        trigger: 'change'
                    }
                ],
                time: [
                    {
                        required: true,
                        message: '请填写预约时间',
                        trigger: 'bur'
                    }
                ],
                hospital: [
                    {
                        required: true,
                        message: '请选择医院',
                        type: 'number',
                        trigger: 'change'
                    }
                ],
                patientName: [
                    {
                        required: true,
                        message: '请填写患者姓名',
                        trigger: 'blur'
                    }
                ],
                phone: [
                    {
                        required: true,
                        message: '请填写电话',
                        trigger: 'blur'
                    }
                ],
                date: [
                    {
                        required: true,
                        message: '请选择预约日期',
                        type: 'date',
                        trigger: 'change'
                    }
                ],
                age: [
                    {
                        required: true,
                        message: '请填写年龄',
                        trigger: 'blur'
                    }
                ],

                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                mode: [
                    {
                        required: true,
                        message: '请选择预约方式',
                        trigger: 'change'
                    }
                ],
                type: [
                    {
                        required: true,
                        message: '请选择就诊类型',
                        trigger: 'change'
                    }
                ],
                action: [
                    {
                        required: true,
                        message: '请选择行动是否方便',
                        trigger: 'change'
                    }
                ],
                service: [
                    {
                        required: true,
                        message: '请选择陪诊类型',
                        type: 'number',
                        trigger: 'change'
                    }
                ]
            }, //表单验证
            list: [],
            pagesize: 10,
            pageindex: 1,
            total: 0,
            current: 1,
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '订单号',
                    width: 160,
                    key: 'OrderNum'
                },
                {
                    title: '预约人',
                    width: 130,
                    key: 'ApplyUser'
                },
                {
                    title: '联系方式',
                    width: 130,
                    key: 'UserPhone'
                },
                {
                    title: '预约时间',
                    width: 110,
                    slot: 'BookingTime'
                },
                {
                    title: '就诊医院',
                    key: 'HospName'
                },
                {
                    title: '区域',
                    width: 90,
                    key: 'FromAreaName'
                },
                // {
                //     title: '行动',
                //     width: 80,
                //     slot: 'IsWalkEasy'
                // },
                {
                    title: '服务名称',
                    width: 100,
                    key: 'OrderServerName'
                },
                {
                    title: '价格',
                    width: 80,
                    key: 'Money_Total'
                },
                {
                    title: '状态',
                    width: 100,
                    slot: 'State'
                },
                {
                    title: '申请时间',
                    width: 110,
                    slot: 'CreateTime'
                },
                {
                    title: '操作',
                    width: 130,
                    align: 'center',
                    slot: 'action'
                }
            ],
            shopList: [],
            loading1: false,
            vipList: [],
            hospList: [],
            shopUserList: [],
            serviceList: [],
            singleList: {},
            ID: '',
            message: '',
            refunfdata: {}
        }
    },
    components: {
        drugsTable
    },
    filters: {
        //处理函数
        stateCn(value) {
            if (value === '0') {
                return '待付款'
            } else if (value === '1') {
                return '已付款'
            } else if (value === '2') {
                return '已确认'
            } else if (value === '3') {
                return '已接单'
            } else if (value === '4') {
                return '已开始'
            } else if (value === '5') {
                return '已完成'
            } else if (value === '6') {
                return '已取消'
            } else if (value === '7') {
                return '已退款'
            } else if (value === '8') {
                return '陪诊完成'
            } else if (value === '9') {
                return '评价完成'
            } else if (value === '10') {
                return '全部完成'
            }
        },
        InTypeCn(value) {
            if (value === '1') {
                return '已预约'
            } else if (value === '2') {
                return '代理预约'
            } else if (value === '3') {
                return '现场挂号'
            }
        },
        IsWalkEasyCn(value) {
            if (value) {
                return '方便'
            } else {
                return '不便'
            }
        },
        SeeTypeCn(value) {
            if (value === '1') {
                return '初诊'
            } else if (value === '2') {
                return '复诊'
            } else if (value === '3') {
                return '检查'
            }
        },
        BookDateCn(value) {
            if (value) {
                return value.substring(0, 10)
            }
        },
        CreateTimeCn(value) {
            if (value) {
                return value.substring(0, 10)
            }
        }
    },
    computed: {
        tableHeight() {
            return window.innerHeight - 240
        }
    },
    mounted() {
        this.shopData()
        this.GetGridJsonList()
        this.GetUser()
        this.HospitalList()
        this.GetGridJson()
        this.GetSelectJson()
    },

    methods: {
        // 全部完成
        async arrive(){
            if (!this.ID) {
                this.$message.error('请先选中记录！')
                return
            }
            let data = {
                OID:this.ID
            }
            this.$confirm('订单是否完成?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(async () => {
                    let res = await OverOrder(data)
                    if (res.state === 'success') {
                        this.seeModal = false
                        this.$message.success('修改成功！')
                        this.GetGridJsonList()
                    }else{
                        this.$message.error(res.message)
                    }
                })
                .catch(() => {})
        },
        // 选择
        selectmodel(selection) {
            if (selection.length > 0) {
                this.ID = selection[0].ID
                console.log(selection)
                this.refunfdata = selection[0]
            } else {
                this.ID = ''
                this.refunfdata = {}
            }
        },
        // 退款
        refund() {
            if (!this.refunfdata.OrderNum) {
                this.$message.error('请先选中记录！')
                return
            }
            let data = {
                outTradeNo: this.refunfdata.OrderNum,
                totalFee: Number(this.refunfdata.Money_Total) * 100,
                refundFee: Number(this.refunfdata.Money_Total) * 100,
                reason: ''
            }
            console.log(data)
            this.$confirm('您确认要退款嘛？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(async () => {
                    let res = await AdRefund(data)

                    if (res.state === 'success') {
                        this.$message.success('退款成功')
                        this.GetGridJsonList()
                    } else {
                        this.$message.error(res.message)
                    }
                })
                .catch(() => {})
        },
        handleDepChange(item) {
            this.formItem.Department = item.ID
            this.formItem.HospDepName = item.Dname
            console.log(this.formItem.Department)
            console.log(this.formItem.HospDepName)
        },
        handlefuwuChange(item) {
            console.log(item)
            this.assignForm.ServiceID = item.ID
            this.assignForm.ServiceName = item.RealName
            console.log(this.assignForm.ServiceName)
        },
        handleHospChange(item) {
            this.formItem.HospName = item.HospName
            this.formItem.ToAddress = item.Address
        },
        handleSelectChange(item) {
            this.formItem.cost = item.ServicePrice
            this.formItem.OrderServerName = item.ServiceName
        },
        handleShopChange(item) {
            console.log(item)
            this.GetShopUserList(item.ID)
        },
        // 获取科室
        async GetSelectJson() {
            let data = {
                parentname: '科室'
            }
            let res = await GetSelectJson(data)
            this.DepartmentList = res.data.rows
        },
        // 获取单条数据
        async GetOrderDetail(ID) {
            let data = {
                ID: ID
            }
            let res = await GetOrderDetail(data)

            if (res.state === 'success') {
                this.singleList = res.data
                this.message = res.message
            }
        },
        // 获取服务
        async GetGridJson() {
            let data = {
                keyword: '',
                type: '陪诊服务'
            }
            let res = await GetGridJson(data)
            this.serviceList = res.data.rows
        },
        // 获取医院列表
        async HospitalList(query) {
            let data = {
                keyword: query
            }
            let res = await HospitalList(data)
            this.hospList = res.data
        },
        // 获取会员列表
        async GetUser(query) {
            let data = {
                keyword: query
            }
            let res = await GetUser(data)
            this.loading1 = false
            const list = res.data.rows.map(item => {
                return {
                    value: item.ID,
                    label: item.RealName
                }
            })
            this.vipList = list
        },
        // 搜索会员
        remoteMethod1(query) {
            if (query !== '') {
                this.loading1 = true

                this.GetUser(query)
            } else {
                this.vipList = []
            }
        },
        // 搜索医院
        remoteMethod2(query) {
            if (query !== '') {
                this.HospitalList(query)
            } else {
                this.hospList = []
            }
        },
        // 打开订单
        handleModel() {
            this.isModal = true
            this.ModalTitle = '创建订单'
            this.formItem = {
                ID: '',
                remarks: '',
                disease: '',
                serviceName: '',
                shop: '',
                Department: '',
                mode: '3',
                type: '1',
                action: '1',
                cost: '',
                date: '',
                appointmentName: '',
                sex: '1',
                age: '',
                phone: '',
                patientName: '',
                hospital: '',
                service: '',
                OrderServerName: '',
                HospName: '',
                ToAddress: '',
                FromAddress: '',
                ServiceID: '',
                time: ''
            }
        },
        // 获取门店列表
        async shopData() {
            let res = await shopData()
            this.shopList = res.data.rows
        },
        // 获取服务人员
        async GetShopUserList(SID) {
            let data = {
                SID: SID
            }
            let res = await GetShopUserList(data)
            console.log(res)
            this.shopUserList = res.data
        },
        /* 关闭对话框 */
        async handleClose() {
            let data = {
                ID: this.ID,
                State: '6'
            }
            this.$confirm('此操作将作废该条预约, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(async () => {
                    let res = await OrderEdit(data)
                    if (res.state === 'success') {
                        this.seeModal = false
                        this.$message.success('作废成功！')
                        this.GetGridJsonList()
                    }
                })
                .catch(() => {})
        },
        // 订单确认
        changemodel() {
            console.log(this.refunfdata.State)
            if (!this.ID) {
                this.$message.error('请先选中记录！')
                return
            }
            if (this.refunfdata.State != 1) {
                this.$message.error('记录状态无法确认！')
                return
            }
            let data = {
                ID: this.ID,
                State: '2'
            }
            this.$confirm('订单是否确认?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(async () => {
                    let res = await OrderEdit(data)
                    if (res.state === 'success') {
                        this.seeModal = false
                        this.$message.success('修改成功！')
                        this.GetGridJsonList()
                    }
                })
                .catch(() => {})
        },
        // 关闭提交
        handleFromClose() {
            this.isModal = false
        },
        // 关闭指派
        handleassignModal() {
            this.assignModal = false
        },
        // 打开指派
        assign() {
            if (!this.ID) {
                this.$message.error('请先选中记录！')
                return
            }
            this.assignModal = true
        },
        // 指派提交
        async assignSub() {
            let data = {
                ID: this.ID,
                ServiceID: this.assignForm.ServiceID,
                ServiceName: this.assignForm.ServiceName
            }
            let res = await BindService(data)
            if (res.state === 'success') {
                this.$Message.success(res.message)
                this.assignModal = false
            } else {
                this.$Message.error(res.message)
            }
        },
        // 搜索
        handleSearch() {
            this.pageindex = 1
            this.loading = true
            this.GetGridJsonList()
        },
        //表单提交
        handleSubmit(name, ModalTitle) {
            this.$refs[name].validate(async valid => {
                let dateTime = `${moment(this.formItem.date).format(
                    'YYYY-MM-DD'
                )} ${this.formItem.time}`
                if (valid) {
                    let data = {
                        ID: this.formItem.ID,
                        OrderItem: this.formItem.service,
                        OrderServerName: this.formItem.OrderServerName,
                        HospDepID: this.formItem.Department,
                        HospDepName: this.formItem.HospDepName,
                        HospName: this.formItem.HospName,
                        HospID: this.formItem.hospital,
                        UserName: this.formItem.patientName,
                        UserPhone: this.formItem.phone,
                        UserAge: this.formItem.age,
                        UserSex: this.formItem.sex,
                        UserID: this.formItem.appointmentName,
                        BookingTime: dateTime,
                        Money_Service: this.formItem.cost,
                        IsWalkEasy: Number(this.formItem.action),
                        SeeType: this.formItem.type,
                        InType: this.formItem.mode,
                        Remark: this.formItem.remarks,
                        FromAddress: this.formItem.FromAddress,
                        ToAddress: this.formItem.ToAddress,
                        ShopID: this.formItem.shop,
                        SickName: this.formItem.disease,
                        ServiceName: this.formItem.serviceName,
                        ServiceID: this.formItem.ServiceID
                    }
                    console.log(data)
                    let res = {}
                    if (ModalTitle === '创建订单') {
                        res = await CreateNewAccompany(data)
                    } else {
                        res = await OrderEdit(data)
                    }

                    if (res.state === 'success') {
                        this.$Message.success(res.message)
                        this.isModal = false
                        this.GetGridJsonList()
                    } else {
                        this.$Message.error(res.message)
                    }
                }
            })
        },
        // 获取列表
        async GetGridJsonList() {
            this.ID = ''
            this.refunfdata = {}
            let data = {
                type: 1,
                keyword: this.search.service,
                dateStart:
                    this.search.startDate == ''
                        ? ''
                        : moment(this.search.startDate).format('YYYY-MM-DD'),
                dateEnd:
                    this.search.endDate == ''
                        ? ''
                        : moment(this.search.endDate).format('YYYY-MM-DD'),
                state: this.search.state,
                pagesize: this.pagesize,
                pageindex: this.pageindex
            }
            console.log(data)
            let res = await GetGridJsonList(data)
            if (res.state === 'success') {
                this.list = res.data.rows
                this.total = res.data.records
            }
        },
        // 修改
        ChangeAppointment(row) {
            this.ModalTitle = '修改预约'
            this.isModal = true
            this.formItem = {
                remarks: row.Remark,
                disease: row.SickName,
                Department: row.HospDepID,
                HospDepName: row.HospDepName,
                mode: row.InType,
                type: row.SeeType,
                action: row.IsWalkEasy ? '1' : '0',
                cost: row.Money_Service,
                date: row.BookingTime,
                appointmentName: row.ApplyUser,
                sex: row.UserSex === 1 ? '1' : '0',
                age: row.UserAge,
                phone: row.UserPhone,
                patientName: row.UserName,
                hospital: row.HospID,
                service: row.OrderItem,
                OrderServerName: row.OrderServerName,
                HospName: row.HospName,
                ToAddress: row.ToAddress,
                shop: row.ShopID,
                FromAddress: row.FromAddress,
                ServiceID: row.ServiceID,
                serviceName: row.ServiceName,
                ID: row.ID,
                time: row.BookingTime.substring(11)
            }
        },
        // 查看
        see(ID) {
            this.seeModal = true
            this.ID = ID
            this.GetOrderDetail(ID)
        },
        // 分页
        changePage(num) {
            this.pageindex = num
            this.loading = true
            this.GetGridJsonList()
        },
        changePageSize(num) {
            this.pagesize = num
            this.loading = true
            this.GetGridJsonList()
        },
        handlePrint() {
            // 打印
            // this.list = this.tableData
            // this.isdrugsTable = true
            // setTimeout(() => {
            this.$print(this.$refs.drugsTable) // 使用
            // this.isdrugsTable = false
            // }, 1000)
        }
    }
}
</script>

<style lang="less" scoped>
.table-top-wrapper {
    margin-left: 10px;
}
.is-selected {
    color: #1989fa;
}
.wrap {
    padding-bottom: 10px;
}
.page-wrap {
    position: fixed;
    bottom: 25px;
    left: 230px;
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
}
.page-wrap-total {
    border-radius: 3px;
    padding: 0 10px;
    height: 32px;
    line-height: 32px;
    margin: 0 20px;
    border: 1px solid #dcdee2;
    font-size: 12px;
}
.search-con {
    padding: 10px 0;
    .search {
        &-col {
            display: inline-block;
            width: 200px;
        }
        &-input {
            display: inline-block;
            width: 200px;
            margin-left: 2px;
        }
        &-btn {
            margin-left: 2px;
        }
    }
}
.list-btn {
    margin: 0 5px;
}
.delete-btn {
    background: #fc8675;
    border: none;
}
.edit-btn {
    background: #5ab1ef;
    border: none;
}
</style>